package leraning.urlConnection;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;

public class URLConnection1 {
	public static void main(String[] args) {
		String path = "http://www.cuter.cn/wp-content/uploads/2012/06/1340794468.jpg";
		URLConnection conn = null;
		try {
            URL url=new URL(path);
            conn=url.openConnection();
            BufferedInputStream is=new BufferedInputStream(conn.getInputStream());
            BufferedOutputStream os=new BufferedOutputStream(new FileOutputStream("img/img4.jpg"));
//            String str=null;
            byte[]buf=new byte[1024];
            int len=0;
            while((len=is.read(buf))!=-1){
            	os.write(buf, 0, len);
            	os.flush();
            }
            System.out.println("finished");
            is.close();
            os.close();
            
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
